package com.chinaoly.sdk.base;

import android.app.Activity;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;


import com.chinaoly.sdk.R;
import com.chinaoly.sdk.util.DecorViewUtil;


/**
 * @创建者 吴斌
 * @创建时间 2018/7/18/018 + 14:03
 * @描述： Activity 的抽象类，继承SDK 内的 OlyActivity,抽离业务公共逻辑
 */
public abstract class ChinaolyActivity<Binding extends ViewDataBinding> extends AppCompatActivity {

    protected Binding mBinding;
    /**
     * resumed
     */
    private boolean isResumed = false;
    protected Activity mActivity;
    public final String TAG = ChinaolyActivity.class.getName();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this;
        DecorViewUtil.setWindowStatusBarColor(this,getStatusColor(),true);
    }


    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }



    /**
     * 用于获取传递过来的参数
     */
    protected void getParam() {

    }




    /**
     * 默认 是 theme_blue
     *
     * @return
     */
    protected int getStatusColor() {
        return R.color.lightblue90;
    }


    /**
     * 设置退出的事件,点击物理 回退键 ,或者 app 的回退键
     */
    public final void setBackEvent() {
        finish();
    }

    @Override
    public void onBackPressed() {
        int num = getSupportFragmentManager().getBackStackEntryCount();
        if (num > 1) {
            getSupportFragmentManager().popBackStack();
        } else {
            setBackEvent();
        }
    }

    public final boolean resumed() {
        return isResumed;
    }

    @Override
    public void onPause() {
        super.onPause();
        isResumed = false;
    }

    @Override
    public void onResume() {
        super.onResume();
        isResumed = true;
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (isFinishing()) {
            clearData();
        }
    }

    @CallSuper
    protected void clearData() {

    }
}
